package io.renren.modules.ccs.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.ccs.dao.RecordDao;
import io.renren.modules.ccs.dao.TypeDao;
import io.renren.modules.ccs.entity.RecordEntity;
import io.renren.modules.ccs.entity.TypeEntity;
import io.renren.modules.ccs.service.RecordService;

/**
 * 选题管理业务层实现类
 * @author SongR
 *
 */
@Service("recordService")
public class RecordServiceImpl extends ServiceImpl<RecordDao, RecordEntity> implements RecordService {

	
	@Autowired
	RecordDao recordDao;
	
	@Autowired
	TypeDao typeDao;
	/**
	 * 实现获取我的选题
	 */
	@Override
	public PageUtils queryPageByOwn(Map<String, Object> params) {
//		recordDao.selectRecordByOwn();
		Page<RecordEntity> page = this.selectPage(
		    new Query<RecordEntity>(params).getPage(),
		    new EntityWrapper<RecordEntity>() 
		);
		for(RecordEntity record : page.getRecords()){
			TypeEntity type = typeDao.selectById(record.getRecordType());
			record.setType(type);
		}
		return new PageUtils(page);
	}
	
	/**
	 * 实现获取选题详情
	 */
	@Override
	public RecordEntity queryInfo(Long recordId) {
		RecordEntity record = this.selectById(recordId);
//		List<TypeEntity> types = typeDao.selectList(new EntityWrapper<TypeEntity>());
//		record.setTypes(types);
		return record;
	}
	
	
	
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<RecordEntity> page = this.selectPage(
                new Query<RecordEntity>(params).getPage(),
                new EntityWrapper<RecordEntity>()
        );
        return new PageUtils(page);
    }



	



}
